//package com.it.water.utils.Scoket;
//
//import org.springframework.stereotype.Service;
//
//import javax.sound.sampled.*;
//import java.io.*;
//import java.net.*;
//
//@Service
//public class MicrophoneService {
//
//    public void startRecordingAndSendToPython() {
//        try {
//            AudioFormat format = new AudioFormat(44100, 16, 2, true, true);
//            DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);
//            TargetDataLine line = (TargetDataLine) AudioSystem.getLine(info);
//            //打开麦克风
//            line.open(format);
//            line.start();
//
//            String[] serverAddresses = {"127.0.0.1", "192.168.0.100"}; // 替换成Python端的地址列表
//            int serverPort = 8888; // 替换成Python端的端口
//
//            DatagramSocket socket = new DatagramSocket();
//
//            byte[] buffer = new byte[1024];
//            DatagramPacket packet;
//
//            System.out.println("开始发送音频数据...");
//
//            while (true) {
//                int bytesRead = line.read(buffer, 0, buffer.length);
//                for (String serverAddress : serverAddresses) {
//                    packet = new DatagramPacket(buffer, bytesRead, InetAddress.getByName(serverAddress), serverPort);
//                    socket.send(packet);
//                }
//            }
//
//        } catch (LineUnavailableException | UnknownHostException | SocketException e) {
//            e.printStackTrace();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }
//}